/*
 * @Author: szx
 * @Date: 2022-02-27 15:10:50
 * @LastEditTime: 2022-02-27 15:17:47
 * @Description:
 * @FilePath: \leetcode\400-499\459\459_2.js
 */
/**
 * @param {string} s
 * @return {boolean}
 */
var repeatedSubstringPattern = function (s) {
    const n = s.length;
    let k = 0;
    const next = new Array(n).fill(0);
    for (let i = 1; i < n; i++) {
        while (k > 0 && s[i] != s[k]) k = next[k - 1];
        if (s[i] === s[k]) k++;
        next[i] = k;
    }
    if (next[n - 1] > 0 && s.length % (s.length - next[n - 1]) === 0) return true;
    else return false;
};
console.log(repeatedSubstringPattern('abab'));
